package com.wyg.epcommonbase.common.util.file;

import lombok.SneakyThrows;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;

/**
 * @Author: WangYongGan
 * @Date: 2021/11/11 11:13
 * @Description:
 */
public class StreamUtil {
    @SneakyThrows
    public static String streamToString(InputStream in) {
        String res = "";
        String line;
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in));
        while ((line = bufferedReader.readLine()) != null)
            res += line+"\n";
        in.close();
        return res;
    }

    @SneakyThrows
    public static String readerToString(Reader reader) {
        String res = "";
        String line;
        BufferedReader bufferedReader = new BufferedReader(reader);
        while ((line = bufferedReader.readLine()) != null)
            res += line+"\n";
        reader.close();
        return res;
    }
}
